package com.example.bdmanagerapplication

import android.graphics.Color
import android.provider.CalendarContract.Colors
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.bdmanagerapplication.databinding.ItemLayoutBinding

class RecordsAdapter(private val itemList: List<PoiEntity>, private val listener: CallBack) :
    RecyclerView.Adapter<RecordsAdapter.CustomViewHolder>() {

    class CustomViewHolder(private val binding: ItemLayoutBinding) : RecyclerView.ViewHolder(binding.root) {
        fun bind(item: PoiEntity, listener: CallBack, position: Int) {
            binding.textViewContent.text = item.name
            //binding.buttonAction.text = if (item.isClient == 1) "√" else "录入"
            binding.mAreaTV.text=item.area
//            binding.buttonAction.setOnClickListener {
//                if(item.isClient==0){
//                    listener.addItemClick(item, position)
//                }
//            }
            binding.nearAction.setOnClickListener {
                listener.itemNearClick(item,position)
            }
            binding.navigateAction.setOnClickListener {
                listener.navigateClick(item,position)
            }
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CustomViewHolder {
        val binding = ItemLayoutBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        return CustomViewHolder(binding)
    }

    override fun onBindViewHolder(holder: CustomViewHolder, position: Int) {
        holder.bind(itemList[position], listener, position)
    }

    override fun getItemCount(): Int {
        return itemList.size
    }

    interface CallBack {
        fun addItemClick(data: PoiEntity, position: Int)
        fun itemNearClick(data: PoiEntity, position: Int)
        fun navigateClick(data: PoiEntity, position: Int)
    }
}